package com.ruoyi.classai.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.classai.domain.AnalysisModeRel;
import org.springframework.stereotype.Service;
import com.ruoyi.classai.mapper.EwcHomeworkSubmissionMaterialsMapper;
import com.ruoyi.classai.domain.EwcHomeworkSubmissionMaterials;
import com.ruoyi.classai.service.IEwcHomeworkSubmissionMaterialsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;

/**
 * 作业提交资料Service业务层处理
 * 
 * @author lcj
 * @date 2025-02-28
 */
@Service
public class EwcHomeworkSubmissionMaterialsServiceImpl extends ServiceImpl<EwcHomeworkSubmissionMaterialsMapper, EwcHomeworkSubmissionMaterials> implements IEwcHomeworkSubmissionMaterialsService {


    @Override
    public void updateByFileName(AnalysisModeRel analysisModeRel,String aiResult) {
        UpdateWrapper<EwcHomeworkSubmissionMaterials> queryWrapper = Wrappers.update();
        queryWrapper.eq("analysis_id", analysisModeRel.getTask_id());
        EwcHomeworkSubmissionMaterials ewcHomeworkSubmissionMaterials= new EwcHomeworkSubmissionMaterials();
        ewcHomeworkSubmissionMaterials.setAnalysisVideo(analysisModeRel.getFilePath());
        String scoreStr = analysisModeRel.getScore();
        BigDecimal score = scoreStr == null||scoreStr.equals("") ? BigDecimal.ZERO : new BigDecimal(scoreStr);
        ewcHomeworkSubmissionMaterials.setScore(score);
        ewcHomeworkSubmissionMaterials.setAnalysisMsg(analysisModeRel.getAnalysis_msg());
        ewcHomeworkSubmissionMaterials.setAimodelDescriotion(aiResult);
        ewcHomeworkSubmissionMaterials.setSynthesisSpeed(analysisModeRel.getSynthesisSpeed());
        ewcHomeworkSubmissionMaterials.setSynthesisGesture(analysisModeRel.getSynthesisGesture());
        ewcHomeworkSubmissionMaterials.setSynthesisRhythm(analysisModeRel.getSynthesisRhythm());
        ewcHomeworkSubmissionMaterials.setType(analysisModeRel.getType());
        this.update(ewcHomeworkSubmissionMaterials,queryWrapper);
    }

    @Override
    public void updateByFileNameForFail(AnalysisModeRel analysisModeRel) {
        UpdateWrapper<EwcHomeworkSubmissionMaterials> queryWrapper = Wrappers.update();
        queryWrapper.eq("analysis_id", analysisModeRel.getTask_id());
        EwcHomeworkSubmissionMaterials ewcHomeworkSubmissionMaterials= new EwcHomeworkSubmissionMaterials();
        ewcHomeworkSubmissionMaterials.setAnalysisMsg(analysisModeRel.getAnalysis_msg());
        this.update(ewcHomeworkSubmissionMaterials,queryWrapper);


    }
}
